<template>
	<view class="parent-box">
		<view class="customer_name">{{cname}}</view>
		<mescroll-body @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<view class="items-box">
				<ClockInRecordInfo v-for="item in dataList" :key="item.id" :data="item" :currentTime="currentTime">
				</ClockInRecordInfo>
			</view>
		</mescroll-body>

	</view>
</template>

<script>
	import ClockInRecordInfo from './clockInRecordInfo.vue'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {
		list
	} from '@/common/api/JzzxCheckIn.js'
	export default {
		mixins: [MescrollMixin],
		components: {
			ClockInRecordInfo
		},
		props: ['cname', 'cid'],
		data() {
			return {
				downOption: {
					offset: 80,

				},
				upOption: {
					page: {
						size: 10
					},

					empty: {
						tip: '暂无相关数据'
					}
				},
				dataList: [],
				queryParams: {
					customerId: this.cid,
					flg: '1',
					pageNum: 1,
					pageSize: 10
				}
			}
		},
		computed: {
			currentTime: function() {
				return new Date().getTime()
			}
		},
		methods: {
			refresh() {

				this.canReset && this.mescroll.resetUpScroll() // 重置列表数据为第一页
				this.canReset && this.mescroll.scrollTo(0, 0) // 重置列表数据为第一页时,建议把滚动条也重置到顶部,避免无法再次翻页的问题  
				this.canReset = true // 过滤第一次的onShow事件,避免初始化界面时重复触发upCallback, 无需配置auto:false

			},
			async upCallback(page) {
				this.queryParams.pageNum = page.num; // 页码, 默认从1开始
				this.queryParams.pageSize = page.size;
				if (this.queryParams.pageNum == 1) {
					this.dataList = []
				}
				var res = await list({
					...this.queryParams
				})
				console.log(res)
				this.dataList = this.dataList.concat(res.rows)

				this.mescroll.endBySize(this.dataList.length, res.total)
			}

		}
	}
</script>

<style scoped lang="scss">
	.parent-box {
		background-color: #F6F6F6;
	}

	.customer_name {
		border-left: 6rpx solid #087AFC;
		padding: 0rpx 20rpx;
		margin: 40rpx 20rpx 20rpx;
	}
</style>